// https://leetcode.cn/problems/binary-number-with-alternating-bits/
// Created by ade on 2022/8/12.
//
#include <iostream>

using namespace std;

class Solution {
public:
    bool hasAlternatingBits(int n) {
        int end = n % 2 == 0;
        while((end ^ (n % 2)) == 1){
            end = !end;
            n >>= 1;
        }
        return n == 0;
    }
};

int main() {
    Solution so;
    int a = 5;// 101 10
    auto res = so.hasAlternatingBits(a);
    cout << res << endl;
    return 0;
}
